package com.example.View.Renderers;

import java.util.HashMap;
import java.util.Map;

import com.example.util.Figure;
import com.example.R;
import com.example.View.Projection;
import com.example.models.Tower;
import com.example.models.Unit;

import android.content.res.*;
import android.graphics.*;
import android.util.Log;

public class GeneralRenderer extends FigureRendererBase {

    // The paint to be used for rendering general figures (such as arrows)
    private Paint normalPaint;

    private Map<String, Bitmap> iconByName;

    /**
     * Constructs a GeneralRenderer
     */
    public GeneralRenderer(Resources resources) {
        super(resources);
        normalPaint = new Paint();
        normalPaint.setStyle(Paint.Style.FILL_AND_STROKE);
        normalPaint.setARGB(255, 255, 255, 0);
        normalPaint.setAntiAlias(true);
        iconByName = new HashMap<String, Bitmap>();
        iconByName.put("ArrowLeft", createBitmap(R.drawable.arrow_left));
        iconByName.put("ArrowRight", createBitmap(R.drawable.arrow_right));
        iconByName.put("ArrowStright", createBitmap(R.drawable.arrow_stright));
    }

    /**
     * Renders a given figure
     * @param canvas The canvas on which (and using which) this figure is rendered
     * @param projection The translation between the model coordinate system and the view coordinate system.
     * @param figure The figure to be rendered.
     */
    @Override
    public void render(Canvas canvas, Projection projection, Figure figure) {
    	Bitmap bitmap = getBitmap(figure);
    	canvas.drawBitmap(bitmap, figure.getX() * projection.getPixelsPerCell() - projection.getX(), figure.getY() * projection.getPixelsPerCell() - projection.getY() - getBitmap(figure).getHeight() + projection.getPixelsPerCell(), normalPaint);
	}

    /**
	 * Returns the bitmap to be used for a given building according to player
	 */
    protected Bitmap getBitmap(Figure figure) {
    	String name = figure.getName();
        Bitmap bitmap = iconByName.get(name);
        return (bitmap);
    }

}
